# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2024/3/24
desc: 
sample: 
"""
import hashlib
import random
import time

import requests


host = 'http://121.11.97.201:9088/'


def getMd5(data):
    # 创建MD5对象
    md5_hasher = hashlib.md5()
    # 将字符串转换为字节，然后更新MD5对象
    md5_hasher.update(data.encode())
    # 生成最终的MD5哈希值
    md5_digest = md5_hasher.hexdigest()
    return md5_digest

def md5_test():
    url =host+'/pinter/com/userInfo'
    phoneNumber = ["130", "131", "138", "145", "146", "147", "150",
                   "151", "152", "172", "174", "175", "180", "181","182", "198"]
    phoneNum_pfix = random.choice(phoneNumber)
    phoneNum=phoneNum_pfix+str(random.randint(10000000,99999999))
    milliseconds = int(time.time() * 1000)
    #md5是不是安全的 加密算法  撞库问题 摘要算法指纹算法 加盐
    data = {"phoneNum": "123434",
     "optCode": "testfan",
     "timestamp": "12112121212", "sign": "your sign data"}
    data['phoneNum']=phoneNum
    data['timestamp'] = milliseconds
    to_sign=f'{phoneNum}testfan{milliseconds}'
    sign=getMd5(to_sign)
    data['sign'] = sign
    print(data)
    res = requests.post(url, json=data)
    print(res.text)
    assert res.status_code == 200
    assert res.json().get('code')=='0'

if __name__ == '__main__':
    #md5_test()
    print(getMd5('root'))
    print(getMd5('root'))